// packageA/mycomponent/goodsComponent/plugin/projectCardModule/projectCardModule.js
const App = getApp();
const GetProjectsByGoodsIdUrl = App.getNetAddresss("plugin.store-projects.frontend.project.get-list-by-goods-id");
var location = require("../../../../../../mybehaviors/location/location");
let Location = null;
Component({
  /**
   * 组件的属性列表
   */
  behaviors: [location],
  properties: {
    goodsId: {
      type: Number,
      value: null,
    },
  },
  lifetimes: {
    attached() {
      this._getLocation((res,point) => {
        Location = { point: point };
        this.getProjects();
      });
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    projects: [],
    ProjectNameLang: "项目",
  },

  /**
   * 组件的方法列表
   */
  methods: {
    getProjects() {
      let point = App.qqMapTransBMap(parseFloat(Location.point.lng), parseFloat(Location.point.lat));
      App._getNetWork({
        url: GetProjectsByGoodsIdUrl,
        data: {
          goods_id: this.data.goodsId,
          lng: point.lng,
          lat: point.lat,
        },
        success: ({ data: { data } }) => {
          this.setData({
            projects: data,
          });
        },
      });
    },
    getProjectNameLang() {
      const basicInfo = wx.getStorageSync("yz_basic_info");
      if (basicInfo.lang?.store_projects?.project) {
        this.setData({
          ProjectNameLang: basicInfo.lang.store_projects.project,
        });
      }
    },
  },
});
